<?php
class Guest_books extends Public_Controller
{
	function __construct()
	{
		parent::__construct();
	}
	
	function index()
	{
		$data['slug'] = 'main';
		$data['guests'] = new guest_book;
		$data['guests']->order_by('id','desc')->get_page();
		$this->template->build('index',$data);
	}
	
	function save()
	{
		if($_POST)
		{
			$guest = new guest_book;
			$guest->from_array($_POST);
			$guest->save();
			redirect('guest_books');
		}
	}
	
	function delete($id)
	{
		if(is_login('ผู้ดูแลระบบ'))
		{
			$guest = new guest_book($id);
			$guest->delete();
			set_notify('success','ลบข้อมูลเรียบร้อยแล้วค่ะ');
			redirect('guest_books');
		}
		else
		{
			redirect('guest_books');
		}
	}
}
?>